package com.graduation_design.modules.admin.controller;

import cn.hutool.core.map.MapUtil;
import com.graduation_design.common.lang.Result;
import com.graduation_design.entity.AppRefund;
import com.graduation_design.modules.app.controller.BaseController;
import com.graduation_design.service.AppOrderService;
import com.graduation_design.service.AppRefundService;
import com.graduation_design.service.SysUserService;
import com.graduation_design.utils.RefundStatusUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/refund")
public class AdminRefundController extends BaseController {

    @Resource
    AppRefundService appRefundService;

    @Resource
    AppOrderService appOrderService;

    @GetMapping("/list")
    public Result list(AppRefund appRefund) {
        return Result.success(MapUtil.builder()
                .put("refundStatusList", RefundStatusUtil.getStatusList())
                .put("pageData", appRefundService.pageAdmin(getPage(), appRefund))
                .build()
        );
    }

    @GetMapping("/info/{id}")
    public Result info(@PathVariable Long id) {
        AppRefund appRefund = appRefundService.getById(id);
        return Result.success(MapUtil.builder()
                .put("refund", appRefund)
                .put("order", appOrderService.getOrderInfo(appRefund.getOrderId()))
                .build());
    }

    @PostMapping("/audit")
    public Result audit(@RequestBody AppRefund appRefund) {
        appRefundService.auditAdmin(appRefund);
        return Result.success();
    }
}
